class Solution {
public:
    int removeDuplicates(int A[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		int cur = 0;

		for (int i = 0; i < n; ) {
			int j = i;
			while (j < n && A[j] == A[i]) {
				++j;
			}
			if (j - i > 1) {
				A[cur++] = A[i];
				A[cur++] = A[i];
			} else {
				A[cur++] = A[i];
			}
			i = j;
		}
		return cur;

    }
};